package com.qingcheng.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yuanxin
 * Date:2019/7/15
 * Time:14:39
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    /**
     * 获取用户名
     * @return
     */
    @RequestMapping("/username")
    public Map username(){
        String username = SecurityContextHolder.getContext().getAuthentication().getName();//得到录入账号
        if ("anonymousUser".equals(username)) {
            username = "";
        }
        System.out.println("当前登录用户:"+username);
        Map<String, String> map = new HashMap<>();
        map.put("username",username);
        return map;
    }
}
